#!/usr/bin/env python
# -*- coding: utf-8 -*-
import typing
from dataclasses import MISSING, field

from marshmallow.utils import missing

default_error_messages = {
    "required": "该项为必填字段",
    "null": "该项不能为空(null)",
    "validator_failed": "非法的字段值",
}


def _field(
        *,
        validate: typing.Optional[
            typing.Union[
                typing.Callable[[typing.Any], typing.Any],
                typing.Iterable[typing.Callable[[typing.Any], typing.Any]],
            ]
        ] = None,
        error_messages: str = None,
        allow_none: typing.Optional[bool] = None
):
    """
    根据需要，参考 `marshmallow.fields.Field.__init__` 的参数，提供新参数
    """
    if error_messages is None:
        error_messages = default_error_messages
    result = {"validate": validate, "error_messages": error_messages, "allow_none": allow_none}
    return {k: v for k, v in result.items() if v is not None}


Field = _field
